#!/bin/sh

DIFS=' 
'

prefix="/usr"
exec_prefix="/usr"

ganglia_prefix="$prefix"
ganglia_exec_prefix="$exec_prefix"
ganglia_bindir="/usr/bin"
ganglia_libdir="/usr/lib"
ganglia_includedir="/usr/include"
ganglia_datarootdir="/var/lib/ganglia"
ganglia_cflags="-g -O2 -fno-strict-aliasing -Wall -D_REENTRANT"
ganglia_ldflags=" -L/usr/lib"
ganglia_libs="-ldl -lnsl -lnsl -lpcre -lexpat -lconfuse -lapr-1 -lpthread "
ganglia_version="3.1.7"

help=no
version=no

usage="ganglia-config"
usage="$usage [--help] [--version] [--all]"
usage="$usage [--prefix] [--exec-prefix] [--bindir] [--libdir] [--includedir] [--datarootdir]"
usage="$usage [--cflags] [--ldflags] [--libs]"
if [ $# -eq 0 ]; then
    echo "ganglia-config:Error: Invalid option" 1>&2
    echo "ganglia-config:Usage: $usage" 1>&2
    exit 1
fi
output=''
output_extra=''
all=no
prev=''
OIFS="$IFS" IFS="$DIFS"
for option
do
    if [ ".$prev" != . ]; then
        eval "$prev=\$option"
        prev=''
        continue
    fi
    case "$option" in
        -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
           *) optarg='' ;;
    esac
    case "$option" in
        --help|-h)
            echo "Usage: $usage"
            echo "Report bugs to ganglia-developers@lists.sourceforge.net"
            exit 0
            ;;
        --version|-v)
            echo "Ganglia $ganglia_version"
            exit 0
            ;;
        --all)
            all=yes
            ;;
        --prefix)
            output="$output $ganglia_prefix"
            ;;
        --exec-prefix)
            output="$output $ganglia_exec_prefix"
            ;;
        --bindir)
            output="$output $ganglia_bindir"
            ;;
        --libdir)
            output="$output $ganglia_libdir"
            ;;
        --includedir)
            output="$output $ganglia_includedir"
            ;;
	--datarootdir)
	    output="$output $ganglia_datarootdir"
	    ;;
        --cflags)
            output="$output -I$ganglia_includedir"
            output_extra="$output_extra $ganglia_cflags"
            ;;
        --ldflags)
            output="$output -L$ganglia_libdir"
            output_extra="$output_extra $ganglia_ldflags"
            ;;
        --libs)
            output="$output -lganglia"
            output_extra="$output_extra $ganglia_libs"
            ;;
        * )
            echo "ganglia-config:Error: Invalid option" 1>&2
            echo "ganglia-config:Usage: $usage" 1>&2
            exit 1;
            ;;
    esac
done
IFS="$OIFS"
if [ ".$prev" != . ]; then
    echo "ganglia-config:Error: missing argument to --`echo $prev | sed 's/_/-/g'`" 1>&2
    exit 1
fi
if [ ".$output" != . ]; then
    if [ ".$all" = .yes ]; then
        output="$output $output_extra"
    fi
    echo $output
fi

